package com.qxczh.common.exceptionhandler;

import com.qxczh.common.dto.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName GlobalExceptionHandler
 * @Description TODO
 * @Author Gaosl
 * @Date 23:48 2020/1/21
 * @Version 1.0
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.warn("执行了"+e.getClass().toString().substring(16)+"异常处理...");
    }



    /**
     * 处理部分操作失败业务异常
     * @author Gaosl
     * @date 23:48 2020/1/21
     * @param e
     * @return com.snow.campuslink.project.result.Result
     **/
    @ExceptionHandler(PartFailBusinessException.class)
    @ResponseBody
    public Result partFail(PartFailBusinessException e){
        e.printStackTrace();
        return Result.warn(e.getMessage());
    }

    /**
     * 处理操作失败业务异常
     * @author Gaosl
     * @date 23:48 2020/1/21
     * @param e
     * @return com.snow.campuslink.project.result.Result
     **/
    @ExceptionHandler(FailBusinessException.class)
    @ResponseBody
    public Result fail(PartFailBusinessException e){
        e.printStackTrace();
        return Result.error(e.getMessage());
    }
}
